import av
import constant as Const

def check_ret(message, ret):
	if ret != Const.ACL_SUCCESS:
		raise Exception("{} failed ret = {}, hex(ret) = {}".format(message, ret, hex(ret)))

def align(ori_length, align_size):
	return ((ori_length + align_size - 1) // align_size) * align_size

def get_video_total_frames(file):
	container = av.open(file)
	video_stream = next(s for s in container.streams if s.type == 'video')
	total_frame_count = 0

	for packet in container.demux(video_stream):
		for _ in packet.decode():
			total_frame_count += 1
		container.close()
		return total_frame_count
